package me.bcloud.web.servlet.manager;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import me.bcloud.web.domain.JobConfig;
import me.bcloud.web.service.JobConfigService;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
@Controller
public class InsertServlet extends HttpServlet {

	@Resource
	JobConfigService jobConfigService;
	public void setJobConfigService(JobConfigService jobConfigService) {
		this.jobConfigService = jobConfigService;
	}
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String other=req.getParameter("other");
		JobConfig newjobConfig=new JobConfig();
		try {
			BeanUtils.populate(newjobConfig, req.getParameterMap());
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if (other.equals("")) {
			jobConfigService.insert(newjobConfig);
			
	
		}else {
			String[] others=other.split(",");
			jobConfigService.insert(newjobConfig, others);
			
		}
		resp.sendRedirect("list");
	
	
		
	}
}
